package com.txhy.certificatechain.ui.manager;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.FutureTarget;
import com.txhy.certificatechain.R;

import java.io.File;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: ImageLoaderManager.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 图片加载管理
 * 创建时间: 2018/9/19 17:54
 * 更新时间：2018/9/19 17:54
 * -----------------------------------------------------------------
 * 2018/9/19 17:54: 创建 ImageLoaderManager.java (侯建军);
 * -----------------------------------------------------------------
 */
public class ImageLoaderManager {
    public static void LoadImage(Context context, String imgUrl, ImageView imageView) {
        Glide.with(context)
                .load(imgUrl)
                .placeholder(R.mipmap.default_img)
                .dontAnimate() //解决圆形图显示占位图问题
                .error(R.mipmap.default_img)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }
    /**
     * 缓存图片到本地
     */
    public static File CacheFile(Context context, String imgUrl){
        File cacheFile = null;
        FutureTarget<File> future = Glide.with(context)
                .load(imgUrl)
                .downloadOnly(500, 500);
        try {
            cacheFile = future.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cacheFile;
    }
}

